﻿using Commons.Collections;

using CY_MVC;
using NVelocity.App;
using NVelocity.Runtime;

namespace ViewNVelocity
{
    internal class TemplateContext
    {
        private static VelocityEngine Velocity;
        private readonly static object Lockobject = new object();
        public static VelocityEngine GetVelocity()
        {
            if (Velocity == null)
            {
                lock (Lockobject)
                {
                    if (Velocity == null)
                    {
                        Velocity = new VelocityEngine();
                        //使用设置初始化VelocityEngine       
                        var props = new ExtendedProperties();

                        props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, StaticConfig.RootPath);
                        props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");

                        Velocity.Init(props);
                    }
                }
            }
            return Velocity;
        }
    }
}
